#ifndef __APP_BUFFER_H_
#define __APP_BUFFER_H_
#include <stdint.h>
#include <pthread.h>

//子缓冲区
typedef struct {
    uint8_t *data_prt;
    int data_len;
    int total_len;
} app_buffer_sub_t;

//父缓冲区
typedef struct {
    app_buffer_sub_t *sub_buffer[2];
    int read_index;
    int write_index;
    pthread_mutex_t read_lock; //读锁
    pthread_mutex_t swap_lock; //交换锁

} app_buffer_t;




/**
 * @brief 缓冲区初始化
 */
app_buffer_t *app_buffer_init(int size);


/**
 * @brief 向缓冲区进行写操作
 * @return  成功标志 0成功 -1 失败
 */
int app_buffer_write(app_buffer_t *buffer, uint8_t *write_data, int write_data_len);

/**
 * @brief 向缓冲区进行写操作
 * @return  读取的字节数
 */
int app_buffer_read(app_buffer_t *buffer, uint8_t *read_buff, int read_buff_len);

/**
 * @brief 缓冲区销毁
 */
void app_buffer_destroy(app_buffer_t *buffer);

#endif // __APP_BUFFER_H_
